home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / basictut.arc / A1.TXT < prev    next >
Text File  |  1989-01-07  |  9KB  |  218 lines

  1. -----
  2. Introduction to BASIC
  3.  
  4.         |BASIC~ is one of many computer |languages~.  The name BASIC is short for
  5. |B~eginner's |A~ll-purpose |S~ymbolic |I~nstruction |C~ode.  Because it is one of the
  6. easiest computer languages to learn and master, BASIC has become the most
  7. popular language for the computer novice.
  8.  
  9.         BASIC consists of |statements~, |commands~ and |functions~.  These are
  10. English words which have special meaning to the computer.  BASIC |programs~ are
  11. simply many statements, commands and functions grouped together to perform a
  12. specific task.
  13.  
  14.         In the following chapters, new statements, commands and functions will
  15. be introduced to you one at a time.  You then will be given a chance to try
  16. them out and see them in action.  |The most important thing to remember is to~
  17. |try each one out~.  Don't worry about making mistakes, you won't hurt the
  18. computer's feelings.  If you do make a mistake, the computer will tell you so.
  19. If this happens, just try again, a little differently the second time.
  20.  
  21.         Remember to press |F2~ when you are ready to continue.
  22. -----
  23. The PRINT Statement
  24.  
  25.         The first thing we need to learn is how to make the computer write
  26. something on the screen.  This is done with a |PRINT~ statement.  The PRINT
  27. statement tells the computer to write on the screen whatever you put after the
  28. PRINT.
  29.                 |YOU TYPE~                      THE COMPUTER PRINTS
  30.         
  31.                 |PRINT 5~                               5
  32.  
  33.         If you want the computer to write the answer to a math problem, put the
  34. problem after the PRINT.
  35.                 
  36.                 |YOU TYPE~                      THE COMPUTER PRINTS
  37.  
  38.                 |PRINT 3+2~                             5
  39.  
  40.         Now try both of the above examples, by typing what is |under~ the words
  41. |YOU TYPE~ and pressing the |return~ key.  Then remember to press |F2~ to continue.
  42. -----
  43. The PRINT Statement (continued)
  44.  
  45.         If you want the computer to print words on the screen, you have to
  46. enclose the words in quotes (|" "~).
  47.  
  48.                 |YOU TYPE~                      THE COMPUTER PRINTS
  49.  
  50.         |PRINT "Whatever comes to mind."~       Whatever comes to mind.
  51.  
  52.         If you want the computer to print both words and the answer to a math
  53. problem, you must separate the two with either a comma (|,~) or a semi-colon (|;~).
  54.  
  55.                 |YOU TYPE~                      THE COMPUTER PRINTS
  56.  
  57.         |PRINT "The answer to 3+2 is";3+2~      The answer to 3+2 is 5
  58.         |PRINT "The answer to 3+2 is",3+2~      The answer to 3+2 is        5
  59.  
  60.         The difference between using the comma and the semi-colon is the amount
  61. of space the computer leaves between items it prints.  Now try the three
  62. examples above by typing what is under the words |YOU TYPE~.
  63.  
  64. (In IBM BASIC you may omit the semi-colon, but many versions require its use.)
  65. -----
  66. Variable
  67.  
  68.         The next thing you need to understand is a |variable~.  A variable is a
  69. symbol (usually a letter of the alphabet) that is used to represent a number.
  70. A variable can represents various values.  They are extremely important when
  71. programming a computer.  Here is how a variable works:
  72.  
  73.         In the algebraic expression
  74.  
  75.                 |9=X+3~,
  76.  
  77.         |X~ is the variable.  For the expression |9=X+3~ to be true, the value of |X~
  78. must be |6~ (because |9~ and |6+3~ are equal).
  79.  
  80.         In the expression
  81.  
  82.                 |SUM=A+B~,
  83.  
  84.         |SUM~, |A~ and |B~ are variables.  |A~ and |B~ may have any values, and the
  85. variable |SUM~ is the total of those values.
  86. -----
  87. Variable (continued)
  88.  
  89.         As you can see, a variable name may be more than one letter of the
  90. alphabet.  In fact, it can be upto 40 |characters~.  The first character of the
  91. variable must be a letter, but the next 39 can be either letters or numerals.
  92. There are many |reserved words~ that can not be used as variable names.  A list
  93. of those words can be found by looking up |reserved words~ in your IBM BASIC
  94. manual.
  95.  
  96.         Listed are invalid variable names and reasons why they are invalid.
  97.  
  98.         |FAT@~  - All characters must be letters or numerals, |@~ is neither.
  99.         |2TALL~ - The first character must be a letter, |2~ is a numeral.
  100.         |PRINT~ - |PRINT~ is a reserved word, as are all BASIC statements.
  101.  
  102.         It is a good idea to make variable names as descriptive as possible.
  103. If you want to write a program that averages two numbers, use the variable
  104. names |AVERAGE~, |NUM1~ and |NUM2~.  This helps you to identify what the variables
  105. are used for, but it doesn't help the computer.  A variable name directs the
  106. computer to a place in its memory where the value of that variable is stored.
  107. -----
  108. LET Statement
  109.  
  110.         The |LET~ statement assigns an expression to a variable.  In IBM BASIC,
  111. the word LET is optional.  The equal sign is sufficient as in the following
  112. examples:
  113.  
  114.                         |LET A=3~     or     |A=3~
  115.  
  116.         In both of these statements, the value |3~ is assigned to the variable |A~.
  117.  
  118.                     |LET SUM=A+B~     or     |SUM=A+B~
  119.  
  120.         Here, the sum of the variables |A~ and |B~ is assigned to the variable |SUM~.
  121.  
  122.                       |LET K=K+1~     or     |K=K+1~
  123.  
  124.         In algebra the expression |K=K+1~ would be false (how can a number be
  125. equal to itself plus 1?).  But in BASIC this means that the |new~ value of |K~ will
  126. be set equal to the |old~ value of |K~ plus |1~.
  127. -----
  128. PRINT and LET Statements
  129.  
  130.         Until a variable has been assigned a value (by using a LET statement),
  131. it will be equal to zero.  If you use a variable in a PRINT statement, the
  132. value of the variable will be PRINTed, and not the variable name.  Type in the
  133. following five lines to see how the PRINT and LET statements work together.
  134.  
  135.         |PRINT NUM1;NUM2;SUM~
  136.         |LET NUM1=45~
  137.         |LET NUM2=5~
  138.         |SUM=NUM1+NUM2~
  139.         |PRINT "The sum of";NUM1;"and";NUM2;"is";SUM~
  140. -----
  141. Line numbers
  142.  
  143.         As you learned earlier, a program is a group of statements.  In order
  144. for the computer to remember, organize and execute the statements in a program,
  145. each statement must have a |line number~.  The computer performs each
  146. statement in the order of its line number.
  147.  
  148.         In the following statements
  149.  
  150.                 |10~ PRINT 3+2
  151.                 |20~ PRINT 3+3
  152.  
  153.         |10~ and |20~ are line numbers.
  154. -----
  155. LIST Command
  156.  
  157.         Typing |LIST~ and pressing return will print the program currently in
  158. memory.  Type the following program and then type |LIST~ and press return.
  159.  
  160.                 |10 PRINT 3+2~
  161.                 |20 PRINT 3+3~
  162.                 |30 PRINT 3+4~
  163.                 |40 PRINT 3+5~
  164. -----
  165. LIST Command (continued)
  166.  
  167.         The computer normally executes the program in numerical order beginning
  168. with the lowest numbered line.  If you want to put the statement |PRINT 3+1~
  169. before line |10~, then assign it a line number less than 10.
  170.  
  171.         Type in the following:
  172.  
  173.                 |10 PRINT 3+2~
  174.                 |20 PRINT 3+3~
  175.                 |30 PRINT 3+4~
  176.                 |40 PRINT 3+5~
  177.                  |5 PRINT 3+1~
  178.  
  179.         Now type |LIST~ and press return.  The LIST command will display the
  180. program in numerical order.  Conventionally, programs are given line numbers in
  181. increments of 10.  The computer will |re-number~ the lines for you if you type
  182. the word |RENUM~ and press return.  Try this out and then |LIST~ the program
  183. again to see what happens.
  184. -----
  185. RUN Command
  186.  
  187.         The |RUN~ command executes your program.  When you typed in PRINT 3+2
  188. earlier and pressed return, the computer executed the PRINT immediately.  Now
  189. when you place a line number before a statement, the computer places that
  190. statement in its memory and waits for a RUN command to execute the program.
  191.  
  192.         Type in the following, type |RUN~ and press return.
  193.  
  194.                 |10 PRINT 3+1~
  195.                 |20 PRINT 3+2~
  196.                 |30 PRINT 3+3~
  197.                 |40 PRINT 3+4;~
  198.                 |50 PRINT 3+5~
  199.  
  200.         (Note that the semi-colon keeps the |8~ on the same line as the |7~.)
  201. -------
  202. End of Lesson One
  203.  
  204.         This is the end of lesson one.  Review the statements and commands
  205. you've covered in this lesson before going on.  BASIC is an easy language to
  206. learn, but you shouldn't try to learn everything at once.  Take some time to
  207. play with what you've learned before beginning lesson two.
  208.  
  209.     If you are using the BASIC Prof,        |The PC-Prof.~
  210. let me know who you are!  Send your name        |P.O. Box 26~
  211. and address to:                        |Salina, Kansas~
  212.                             |67402-0026~
  213.  
  214.     If you like the Prof, include a contribution ($30 - $50 suggested) to
  215. help support development of additional volumes.  Please copy and share the
  216. Prof. with other IBM P.C. users.
  217. -----
  218.